import {Component, OnInit} from '@angular/core';
import {ModalController} from '@ionic/angular';
import {ToastService} from '../../service/toast.service';

@Component({
    selector: 'app-registered',
    templateUrl: './registered.component.html',
    // styleUrls: ['./registered.component.less'],
})
export class RegisteredComponent implements OnInit {

    constructor(
        public modalController: ModalController,
        private toast: ToastService,
    ) {
    }

    isRequest = false; // 验证码是否正在请求
    timing = 60;  // 验证码倒计时
    verificationCodeTitle = '发送验证码';

    ngOnInit() {
    }

    // 返回上一层（关闭当前model）
    back() {
        this.modalController.dismiss({
            'dismissed': true
        });
    }

    // 获取验证码
    getVerificationCode() {
        this.isRequest = true;
        this.verificationCodeTitle = this.timing + '秒后重试';
        let timer = setInterval(() => {
            this.timing--;
            this.verificationCodeTitle = this.timing + '秒后重试';
            if (this.timing === 0) {
                this.timing = 60;
                clearInterval(timer);
                this.verificationCodeTitle = '获取验证码';
                this.isRequest = false;
            }
        }, 1000);
    }

    // 该功能暂未开放
    toastFun() {
        this.toast.warnToast('该功能暂未开放！');
    }
}
